/**
 * @file   Project1.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Thu Mar 25 05:41:30 2021
 * 
 * @brief  A brief program to get a database of students.
 * 
 * 
 */
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
class Students{
private:
    string id,name;
    map<string,double> course;
    double Average;
public:
    Students(){
	id="";
	name="";
	course.clear();
	Average=0;
    }
    void info1(string _id,string _name){
	id=_id;
	name=_name;
    }
    void info2(string cname,double score){
	course[cname]=score;
    }
    void setAvg(double sc){
        Average=sc;
    }
    double getAvg(){
	return Average;
    }
    string getid(){
	return id;
    }
    map<string,double> getcourse(){
	return course;
    }
    void Printinfo(set<string> courses);
};
void Students::Printinfo(set<string> courses){
    cout<<id<<", "<<name<<", ";
    for(auto j:courses){
	if(course.count(j)){//course j is in the table
	    cout<<fixed<<setprecision(1)<<course[j];
	}
	cout<<", ";
    }
    cout<<fixed<<setprecision(1)<<Average<<endl;
}
bool cmp(Students i,Students j){
    if(i.getid()<j.getid()){
	return true;
    }else{
	return false;
    }
}
int main(){
    string in;
    set<string> allcourse;
    vector<Students> Database;
    map<string,int> getindex;
    while(1){
	getline(cin,in);
	if(in==""){
	    break;
	}
	int type=0;
	for(int i=0;i<in.size();i++){//Student Name and ID?Or ID,Score and Subject?
	    if(in[i]==','){
		type++;
	    }
	}
	if(type==1){//case1:Student name and ID
	    int flag=0;
	    for(int i=0;i<in.size();i++){
		if(in[i]==','){
		    flag=i;
		    break;
		}
	    }
	    string s1=in.substr(0,flag);//substring #1:Student ID;
	    string s2=in.substr(flag+2);//substring #2:Student Name;
	    if(getindex.count(s1)==0){//No such student ID!
		getindex[s1]=Database.size();
		Students stu;
		stu.info1(s1,s2);
		Database.push_back(stu);//register the student.
	    }else{//There exists such an ID,set his/her name
		int index=getindex[s1];
		Database[index].info1(s1,s2);//modify the student information
	    }
	}
	else if(type==2){//case2:ID,course and grades
	    int flag1,flag2;//mark the position of ','
	    flag1=flag2=-1;
	    for(int i=0;i<in.size();i++){
		if(in[i]==','&&flag1==-1){
		    flag1=i;
		}
		else if(in[i]==','&&flag1!=-1){
		    flag2=i;
		}
	    }
	    string s1=in.substr(0,flag1);//s1 marks ID
	    string s2=in.substr(flag1+2,flag2-flag1-2);//s2 marks the course
	    string s3=in.substr(flag2+2);//s3 marks the grade
	    allcourse.insert(s2);
            if(getindex.count(s1)==0){//no such ID!
		getindex[s1]=Database.size();
		Students stu;
		stu.info2(s2,atof(s3.c_str()));
		Database.push_back(stu);
	    }else{//there exists such an ID!set his/her grades
		int index=getindex[s1];
		Database[index].info2(s2,atof(s3.c_str()));
	    }
	}
    }
    cout<<"student id, name, ";
    for(auto i:allcourse){
	cout<<i<<", ";
    }
    cout<<"average"<<endl;
    sort(Database.begin(),Database.end(),cmp);
    for(int i=0;i<Database.size();i++){//calculate the average data
	double sc=0;
	int cnt=0;
	for(auto j:allcourse){
	    if(Database[i].getcourse().count(j)){//have such a course
		sc=sc+Database[i].getcourse()[j];
		cnt++;
	    }
	}
	sc=sc*1.0/cnt;
	Database[i].setAvg(sc);
    }
    for(int i=0;i<Database.size();i++){
	Database[i].Printinfo(allcourse);//print the information of students.
    }
    cout<<", , ";
    double sum=0;
    int count=0;
    for(auto i:allcourse){//find the average score of all the courses
	double total=0;
	int cnt=0;
	int flag=0;//There are some students get this course
	for(int j=0;j<Database.size();j++){
	    if(Database[j].getcourse().count(i)){//FIND the course!
		flag=1;
		total=total+Database[j].getcourse()[i];
		cnt++;
	    }
	}
	double avg=total/cnt;
	sum+=avg;
	count++;
	if(flag==1){
	    cout<<fixed<<setprecision(1)<<avg;
	}
	cout<<", ";
    }
    cout<<fixed<<setprecision(1)<<sum/count<<endl;
}

